interface IPerson {
    firstName : string;
    lastName : string;
    sayHi : () => string
}

let user : IPerson = {
    firstName : "Jane",
    lastName : "Hanks",
    sayHi : () : string => {
        return "Hi there";
    }
};
console.log( "firstName: " + user.firstName );
console.log( "lastName: " + user.lastName );
console.log( user.sayHi() );

interface RunOptions {
    program : string;
    commandline : string[] | string | ( () => string );
}

let options : RunOptions = {
    program : "node",
    commandline : "hello",
};
console.log( options.commandline );

options = {
    program : "node",
    commandline : [ "hello", "world" ],
};
console.log( options.commandline );

options = {
    program : "node",
    commandline : () => {
        return "hello world";
    },
};
let fn = options.commandline;
if( typeof fn === "function" ) {
    console.log( fn );
}

// 索引签名
interface NameInterface {
    [key : number|string] : string;
}
let nameArr : NameInterface = {
    first : "Jane",
    last : "Hanks",
};
console.log( nameArr );
let listArr : NameInterface = {
    0 : "Jane",
    1 : "Hanks",
};
console.log( listArr );

// Typescript 允许接口继承多个接口。 继承使用关键字 extends。
// 单接口继承
interface PersonInterface {
    age : number;
}
interface MuInterface extends PersonInterface{
    instrument : string;
}
let mu  = <MuInterface> {};
mu.age = 10;
mu.instrument = "guitar";
console.log( mu );

// 多接口继承
interface IPerson1 {
    v1 : number;
}
interface IPerson2 {
    v2 : number;
}
interface children extends IPerson1, IPerson2{
    v0 : number;
}
let child = <children> {};
child.v0 = 0;
child.v1 = 1;
child.v2 = 2;
console.log( child );